package com.xuxingcan.findmyvoice.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xuxingcan.findmyvoice.Model.ReceiveMessageModel;
import com.xuxingcan.findmyvoice.R;

import java.text.SimpleDateFormat;

/**
 * Created by xuxingcan on 16-4-4.
 */
public class DetailActivity extends BaseActivity {
    private DisplayImageOptions options = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.drawable.test)          // 设置图片下载期间显示的图片
            .showImageForEmptyUri(R.drawable.test)  // 设置图片Uri为空或是错误的时候显示的图片
            .showImageOnFail(R.drawable.test)       // 设置图片加载或解码过程中发生错误显示的图片
            .cacheInMemory(true)                        // 设置下载的图片是否缓存在内存中
            .cacheOnDisk(true)                          // 设置下载的图片是否缓存在SD卡中
            .build();                                   // 创建配置过得DisplayImageOption对象

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        ReceiveMessageModel model = null;
        String json = getIntent().getStringExtra("json");
        if (json != null) {
            model = new Gson().fromJson(json, ReceiveMessageModel.class);
        }
        findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ImageView mImageView0 = (ImageView) findViewById(R.id.pic0);
        ImageView mImageView1 = (ImageView) findViewById(R.id.pic1);
        ImageView mImageView2 = (ImageView) findViewById(R.id.pic2);
        TextView time = (TextView) findViewById(R.id.time);
        TextView title = (TextView) findViewById(R.id.title);
        TextView content = (TextView) findViewById(R.id.content);
        if (model != null) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            time.setText(sdf.format(model.getCreateDate()));
            title.setText(model.getHead());
            content.setText(model.getContent());
            if (model.getBitmapUrls().size() == 1) {
                ImageLoader.getInstance().displayImage(model.getBitmapUrls().get(0), mImageView0, options);
                findViewById(R.id.pic1_2_layout).setVisibility(View.GONE);
            } else if (model.getBitmapUrls().size() == 2) {
                ImageLoader.getInstance().displayImage(model.getBitmapUrls().get(0), mImageView0, options);
                ImageLoader.getInstance().displayImage(model.getBitmapUrls().get(1), mImageView1, options);
                mImageView2.setVisibility(View.GONE);
            } else if (model.getBitmapUrls().size() == 3) {
                ImageLoader.getInstance().displayImage(model.getBitmapUrls().get(0), mImageView0, options);
                ImageLoader.getInstance().displayImage(model.getBitmapUrls().get(1), mImageView1, options);
                ImageLoader.getInstance().displayImage(model.getBitmapUrls().get(2), mImageView2, options);
            }
        }
    }
}
